﻿''' <summary>
''' 文本数据输出
''' </summary>
''' <remarks></remarks>
Public Class ClassTxtDataOut
    Public Shared nodeSperateChar As String = ">"

    ''' <summary>
    ''' 文本数据输出环数据
    ''' </summary>
    ''' <param name="txtFileName">文本文件名称</param>
    ''' <param name="rings">环数据</param>
    ''' <remarks></remarks>
    Public Sub TextFileOut(ByVal txtFileName As String, ByVal rings() As IClassTypeRing)
        Dim filewrite = My.Computer.FileSystem.OpenTextFileWriter(txtFileName, False, System.Text.Encoding.UTF8)
        Dim tmpNode As TypeNode

        For Each tmpRing As IClassTypeRing In rings
            If tmpRing.isMinRing Then
                filewrite.Write(tmpRing.GetRingNo & ",") '环编号
                For Each tmpNode In tmpRing.getNodeList
                    '循环输出环中节点的数据
                    filewrite.Write(tmpNode.sNodeNo) '环中的节点名称
                    Dim lastNode = tmpRing.getNodeList.GetValue(tmpRing.getNodeList.Length - 1)
                    If Not lastNode.Equals(tmpNode) Then
                        filewrite.Write(nodeSperateChar) '环中的节点名称分割符
                    Else
                        filewrite.Write(",") '数据分割符号
                    End If
                Next
                filewrite.Write(tmpRing.getNodeList.Length) '节点个数

                '末一个节点
                'tmpNode = tmpRing.getStartNode
                filewrite.WriteLine() '换行
            End If
        Next
        filewrite.Flush()
        filewrite.Dispose()
    End Sub

    ''' <summary>
    ''' 文本数据输出环数据
    ''' </summary>
    ''' <param name="txtFileName">文本文件名称</param>
    ''' <param name="ringsList">环数据</param>
    ''' <param name="nodeSperateChar">输出数据节点间分割符合，默认">"</param>
    ''' <remarks></remarks>
    Public Sub TextFileOut(ByVal txtFileName As String, ByVal ringsList As List(Of IClassTypeRing), Optional ByVal nodeSperateChar As String = ">")
        Dim filewrite = My.Computer.FileSystem.OpenTextFileWriter(txtFileName, False, System.Text.Encoding.UTF8)
        Dim tmpNode As TypeNode

        For Each tmpRing As IClassTypeRing In ringsList
            If tmpRing.isMinRing Then
                filewrite.Write(tmpRing.GetRingNo & ",") '环编号
                For Each tmpNode In tmpRing.getNodeList
                    '循环输出环中节点的数据
                    filewrite.Write(tmpNode.sNodeNo) '环中的节点名称
                    Dim lastNode = tmpRing.getNodeList.GetValue(tmpRing.getNodeList.Length - 1)
                    If Not lastNode.Equals(tmpNode) Then
                        filewrite.Write(nodeSperateChar) '环中的节点名称分割符
                    Else
                        filewrite.Write(",") '数据分割符号
                    End If
                Next
                filewrite.Write(tmpRing.getNodeList.Length) '节点个数

                '末一个节点
                'tmpNode = tmpRing.getStartNode
                filewrite.WriteLine() '换行
            End If
        Next
        filewrite.Flush()
        filewrite.Dispose()
    End Sub
    ''' <summary>
    ''' 文本输出点数据
    ''' </summary>
    ''' <param name="txtFileName">文件名称</param>
    ''' <param name="NodeList">节点名称</param>
    ''' <remarks></remarks>
    Public Sub NodeTextOut(ByVal txtFileName As String, ByVal nodeList As List(Of TypeNode))
        Dim filewrite = My.Computer.FileSystem.OpenTextFileWriter(txtFileName, False, System.Text.Encoding.UTF8)
        Dim tmpNode As TypeNode

        filewrite.Flush()
        filewrite.Dispose()
    End Sub
    ''' <summary>
    ''' 文本输出线路信息
    ''' </summary>
    ''' <param name="txtFileName">文件名称</param>
    ''' <param name="lineList">线路节点</param>
    ''' <remarks></remarks>
    Public Sub LineTextOut(ByVal txtFileName As String, ByVal lineList As List(Of TypeLine))
        Dim filewrite = My.Computer.FileSystem.OpenTextFileWriter(txtFileName, False, System.Text.Encoding.UTF8)
        Dim tmpNode As TypeNode

        filewrite.Flush()
        filewrite.Dispose()
    End Sub
End Class
